﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Wicresoft.Busi.BizLogic;
using Wicresoft.Busi.Entity;

public partial class NewMeetingRoom_RoomInfoView : BaseAuthenticationPage
{
    protected void Page_Load(object sender, System.EventArgs e)
    {
        // Put user code to initialize the page here


        if (!Page.IsPostBack)
        {
            initRoomType();
            initRoom();

            if (Request.QueryString["ID"] != null && Request.QueryString["ID"] != "")
            {
                DataTable dt = BLMeetingRooms.GetRoomInfo(int.Parse(Request.QueryString["ID"]));
                if (dt != null)
                {
                    this.ddlRoomType.SelectedValue = dt.Rows[0]["RoomType"].ToString();
                    initRoom();
                    this.ddlRoom.SelectedValue = dt.Rows[0]["ID"].ToString();
                }
                LoadRoomInfo();
            }
            MeetingRooms info = new MeetingRooms(Convert.ToInt32(Request.QueryString["ID"]));
            info.Load();


        }
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
        //
        InitializeComponent();
        base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {

    }
    #endregion

    private void initRoomType()
    {
        DataTable dt = BLDic_MeetingRoom.GetRoomType();
        this.ddlRoomType.DataSource = dt;
        this.ddlRoomType.DataTextField = Dic_MeetingRoom.SQLCOL_PROPERTYNAME;
        this.ddlRoomType.DataValueField = Dic_MeetingRoom.SQLCOL_PROPERTYID;
        this.ddlRoomType.DataBind();
    }

    private void initRoom()
    {
        DataTable dt = BLMeetingRooms.GetMeetingRooms(int.Parse(this.ddlRoomType.SelectedValue), CurrentUser.ID);
        dt.Columns.Add("RoomDesc", typeof(string));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow dr = dt.Rows[i];
            dr["RoomDesc"] = dr[vwMeetingRooms.SQLCOL_ROOMNAME].ToString() + " （座位数：" + dr[vwMeetingRooms.SQLCOL_SEATSCOUNT].ToString() + "人）";
        }
        this.ddlRoom.DataSource = dt;
        this.ddlRoom.DataTextField = "RoomDesc";
        this.ddlRoom.DataValueField = vwMeetingRooms.SQLCOL_ID;
        this.ddlRoom.DataBind();
    }

    private void LoadRoomInfo()
    {
        if (this.ddlRoom == null || this.ddlRoom.Items.Count == 0)
        {
            this.lblRoomType.Text = "";
            this.lblRoomName.Text = "";
            this.lblLocation.Text = "";
            this.lblSeatsCount.Text = "";
            this.imgRoom.ImageUrl = "../images/NoPreview.jpg";
            return;

        }
        MeetingRooms info = new MeetingRooms(int.Parse(this.ddlRoom.SelectedValue));
        info.Load();
        this.ddlRoomType.SelectedValue = info.RoomType.ToString();
        this.lblRoomType.Text = BLDic_MeetingRoom.GetPropertyName(MeetingRoomPropertyType.ROOMTYPE, info.RoomType);
        this.lblRoomName.Text = info.RoomName + "（" + BLDic_MeetingRoom.GetPropertyName(MeetingRoomPropertyType.ROOMSTATUS, int.Parse(info.Flag)) + "）";
        this.lblLocation.Text = info.Location;
        this.lblSeatsCount.Text = info.SeatsCount.ToString();
        if (info.Picture == null || info.Picture.Equals(string.Empty))
            this.imgRoom.ImageUrl = "../images/NoPreview.jpg";
        else
        {
            this.imgRoom.ImageUrl = "../images/MeetingRooms/" + info.Picture;
            this.hlImg.HRef = "../images/MeetingRooms/" + info.Picture;
        }
        this.lblDescript.Text = info.Description;
    }

    protected void ddlRoomType_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        initRoom();
        LoadRoomInfo();
    }

    protected void ddlRoom_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        LoadRoomInfo();
    }

    private System.Data.DataTable dgDevice_OnGetData(object sender, Wicresoft.Web.UI.WebControls.GetDataEventArgs e)
    {

        return BLMeetingRoomDevice.GetMeetingRoomDevice(int.Parse(this.ddlRoom.SelectedValue), e.Paging);
    }

}
